<?php

if(!defined('INEZCMS')){
	exit('Access Denied');
}

switch($act){
    case 'check_user':
	    echo $ezhand->check_user($_POST['username']);
	break;
	
	case 'check_oldpass':
	    echo $ezhand->check_oldpass($_POST['oldpass'],$_POST['ezuserid']);
	break;
	
	case 'check_my_email':
	    $id=$ezhand->check_my_email($_POST['email'],$_POST['dduserid']);
		if($id>0){echo 'false';}
		else{echo 'true';}
	break;
	
	case 'check_my_alipay':
	    $id=$ezhand->check_my_field('alipay',$_POST['alipay'],$_POST['dduserid']);
		if($id>0){echo 'false';}
		else{echo 'true';}
	break;
	
	case 'check_my_tenpay':
	    $id=$ezhand->check_my_field('tenpay',$_POST['tenpay'],$_POST['dduserid']);
		if($id>0){echo 'false';}
		else{echo 'true';}
	break;
	
	case 'check_my_bank_code':
	    $id=$ezhand->check_my_field('bank_code',$_POST['bank_code'],$_POST['bank_code']);
		if($id>0){echo 'false';}
		else{echo 'true';}
	break;
	
	case 'check_email':
	    echo $ezhand->check_email($_POST['email']);
	break;
	
	case 'check_alipay':
	    echo $ezhand->check_alipay($_POST['alipay']);
	break;
	
	case 'check_captcha':
	    session_start();
	    if($_POST['captcha']==$_SESSION["captcha"]){
	        echo 'true';
	    }
	    else{
	        echo 'false';
	    }
	break;
	case 'favorite':
    
        $data["status"]=0;
        $tid=intval($_POST["tid"]);
        if(empty($tid)){
           $data["msg"]="请选择收藏文章!"; 
            echo json_encode($data);
            exit;    
        }
       
        if(empty($userlogininfo)){
           $data["msg"]="请登录后再收藏此文章!"; 
           echo json_encode($data);
           exit;    
        }
        $title=$ezhand->select('thread','title','id="'.$tid.'"');
        if(empty($title)){
           $data["msg"]="此文章不存在!"; 
           echo json_encode($data);
           exit;                
        }
        
        $cdata["tid"]=$tid;
        $cdata["userid"]=$userlogininfo["uid"];
        $cdata["title"]=$title;
        $cdata["adddate"]=time();
        $favid=$ezhand->select('favorite','id','tid="'.$tid.'" and userid='.$userlogininfo["uid"]);
        if(!empty($favid)){
           $data["msg"]="此文章已经收藏过了!"; 
           echo json_encode($data);
           exit;                   
            
        }
        
        $qid = $ezhand->insert('favorite', $cdata, 0); 
        if($qid>0){
            $data["status"]=1;
            $data["msg"]="收藏成功!";
        }else{
              $data["status"]=0;
              $data["msg"]="系统错误，请联系管理员!"; 
        }
        echo json_encode($data);
    
    exit();
    break;
	case 'get_msg':
	    $id = (int)$_GET['id'];
        $ezuser["id"]=$userlogininfo["ezusername"];
	    if(!empty($ezuser['id'])){
			$info=$ezhand->select('message','send_to_id,send_from_id,status,subject,content','id="'.$id.'"');
			if($ezuser['id']==$info['send_to_id'] || $ezuser['id']==$info['send_from_id']){
			    if($info['send_to_id']==$ezuser['id'] && $info['status']==0){
			        $data=array('status'=>1);
			        $ezhand->update('message',$data,'id="'.$id.'"');
			    }
	            echo $msg='<p style=" line-height:20px;">'.$info["content"].'</p>';
			}
			else{
			    $re=json_encode(array('s'=>0,'id'=>102));
		        echo $re;
			}
	    }
		else{
		    $re=json_encode(array('s'=>0,'id'=>101));
		    echo $re;
		}
	break;
	
	case 'userinfo':
	    if($ezuser['id']>0){
			if($msgnum==0){ 
	            $msgsrc="<img src=\"template/".MOBAN."/images/msg1.gif\" border=\"0\" alt=\"短消息\" />";
            }else{
	            $msgsrc="<img src=\"template/".MOBAN."/images/msg0.gif\" border=\"0\" alt=\"您有新的短消息\" /> (".$msgnum.")";
            }
			$userinfo=array('name'=>$dduser['name'],'id'=>$dduser['id'],'money'=>$dduser['money'],'jifenbao'=>$dduser['jifenbao'],'jifen'=>$dduser['jifen'],'level'=>$dduser['level'],'msgsrc'=>$msgsrc,'avatar'=>a($dduser['id']));
			$re=array('s'=>1,'user'=>$userinfo);
		    echo dd_json_encode($re);
		}
		else{
		    $re=array('s'=>0);
		    echo dd_json_encode($re);
		}
	break;
	
	case 'comment':
	    if($dduser['id']==''){
			$re=dd_json_encode(array('s'=>0,'id'=>10));
		    echo $re;continue;
		}
		$comment=reg_content($_GET['comment']);
		$mall_id=(int)$_GET['mall_id'];
		$fen=(int)$_GET['fen'];
		if($mall_id==0 || $fen==0 || $comment==''){
		    $re=dd_json_encode(array('s'=>0,'id'=>11));
		    echo $re;continue;
	    }
		$lasttime=$ezhand->select('mall_comment','addtime',"uid=".$dduser['id']." and mall_id='".$mall_id."'"); //上次评论时间
	    if(TIME-$lasttime<$webset['comment_interval']){
	        $re=dd_json_encode(array('s'=>0,'id'=>33));
		    echo $re;continue;
	    }
		$fen=$fen==0?5:$fen;
		$field_arr=array('mall_id'=>$mall_id,'uid'=>$dduser['id'],'fen'=>$fen,'content'=>$comment,'addtime'=>TIME);
		$ezhand->insert('mall_comment',$field_arr);
		$re=dd_json_encode(array('s'=>1,'id'=>0));
		echo $re;
	break;
	

	case 'pinyin':
	    $title=$_POST['title'];
		if(!class_exists('pinyin')){include(DDROOT.'/comm/pinyin.class.php');}
		echo $pinyin=fs('pinyin')->re($title);
	break;
	

}
$ezhand->close();
unset($ezhand);
unset($webset);
exit;
?>